package com.netx.ebs;
import com.netx.generics.basic.Logger;
import com.netx.data.Database;
import com.netx.data.Connection;
import com.netx.data.DatabaseException;


class EbsLogger implements Logger {
	
	private final Logger _parent;
	private final Database _db;
	
	public EbsLogger(Logger parent, Database db) {
		super();
		_parent = parent;
		_db = db;
	}

	public LEVEL getLevel() {
		return _parent.getLevel();
	}

	public void setLevel(LEVEL level) {
		_parent.setLevel(level);
	}

	public void info(String message) {
		_parent.info(message);
	}

	public void warning(String message) {
		_parent.warning(message);
	}
	
	public void warning(String message, Throwable t) {
		_parent.warning(message, t);
	}

	public void error(String message, Throwable t) {
		if(getLevel() != LEVEL.NONE) {
			try {
				Connection c = _db.getConnection();
				Entities.getErrors(c).save(0, t, null);
				c.close();
			}
			catch(DatabaseException de) {
				_parent.error(message, t);
				_parent.error("error in EbsLogger", de);
			}
		}
	}

	public void error(Throwable t) {
		error(null, t);
	}

}
